<?php defined('SYSPATH') OR die('No direct access allowed.');

class Home_Controller extends MyTemplate_Controller {

        protected $validacao;

    function __construct(){
        parent::__construct();
        $this->validacao = new Login_Model();
        $this->template->backBtn = false;
//        $this->template->titulo = kohana::lang('own_strings.tituloPadrao');
    }

    public function index() {
        if(!$this->validacao->verificarUsuarioLogado()){
            $this->template->body = new View('telaLogin');
            $this->template->body->formAction = 'home/logar';
        } else{
            url::redirect('index/index');
        }
    }
    
    public function logar() {

        $usuario = $this->input->post('username');
        $senha     = $this->input->post('password');

        $validacao = new Login_Model();
        if ( $validacao->logar($usuario, $senha) ) {
                url::redirect('index/index');
        } else {
                $this->exibirTelaLogin();
                $this->template->body->msgErro = 'Não Logou!!!';
        }

    }
    
    public function deslogar() {
        $validacao = new Login_Model();
        $validacao->deletarSessionUsuario();
        url::redirect('home/index');
    }

}

?>
